<template>
  <div id='recharge'>
    <com-head :opacity='0'>金币购买</com-head>
    <div class="recharge" v-for="(item,index) in item" :key="index">
        <p>以太坊地址：<span>{{address}}</span></p>
        <p>挂卖数量：<span>{{item.num}}</span></p>
        <p>折合价格: <span>&yen;{{item.zongjia}} <img src="../assets/image/bitebi.png"> {{item.btc}}<img src="../assets/image/yitai.png">{{item.eth}}</span></p>
    </div>
    <div class="item"><span>打款凭证</span></div>
    <div class="uploadimg">
        <div class="upload" @click="portrait">
        <div class="yulan" v-if="img1"><img :src="`http://${img1}`"></div>
        <input class="imginp" ref="portrait" name="imgLocal" id="imgLocal" type='file' accept="image/*" @change="shangchuan"/>
        <div class="box">
            <i class="iconfont icon-tianjia"  v-if="!img1"></i>
            <span  v-if="!img1">上传截图</span>
            </div>
        </div>
    </div>
    <div class="item"><span>备注信息</span></div>
    <div class="message">
        <textarea v-model="content" placeholder="请输入备注信息"></textarea>
    </div>
    <com-button :click="submitTo">提交</com-button>

  </div>
</template>

<script>
export default {
  name: "recharge",
  data() {
    return {
      item: [],
      address: "",
      img1: "",
      imgid1: "",
      content: ""
    };
  },

  computed: {},

  created() {},

  mounted() {
    this.loading();
  },

  methods: {
    loading() {
      this.axios
        .post("apiindex/goldlist", {
          token: this.token()
        })
        .then(({ data }) => {
          
          if (data.code === "200") {
            this.address = data.data.address;
            this.item = data.data.list;
          } else if (data.code === "204") {
            this.$bus.$emit("toast", data.data);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    submitTo() {
      this.axios
        .post("apiindex/goldback", {
          token: this.token(),
          imgurl: this.imgid1,
          content: this.content
        })
        .then(({ data }) => {
          
          if (data.code === "200") {
            this.$router.push("userCenter");
            this.$bus.$emit("toast", data.data);
          } else if (data.code === "204") {
            this.$bus.$emit("toast", data.data);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    portrait() {
      this.$refs.portrait.click(); // 获取ref为portrait的元素相当于获取id为portrait的元素
    },
    // 上传图片
    shangchuan(e) {
      var self = this;
      let file = e.target.files[0]; // 上传照片
      /* eslint-disable no-undef */
      let formData = new FormData(); // 创建form对象
      formData.append("imgurl", file); // 通过append向form对象添加数据
      // formData.append("token", this.token()); // 添加form表单中其他数据
      console.log(formData.get("imgurl")); // FormData私有类对象，访问不到，可以通过get判断值是否传进去
      let config = {
        emulateJSON: true,
        withCredentials: false,
        headers: { "Content-Type": "multipart/form-data" }
      };
      this.$axios
        .post(
          "http://kuaibb.cadhx.com/index.php/index/apiupload/doupload",
          formData,
          config
        )
        .then(({ data }) => {
          if (data.code === "200") {
            
            this.img1 = data.img;
            this.imgid1 = data.imgid;
          } else if (data.code === "204") {
            this.$bus.$emit("toast", data.data);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  }
};
</script>
<style lang='scss' scoped>
#recharge {
  padding: 80px 32px;
  box-sizing: border-box;
  .com_button {
    margin-top: 60px;
    width: 686px;
  }
  .recharge {
    padding: 15px 0px;
    box-sizing: border-box;
    border-bottom: 1Px solid #ddd;
    font-size: 32px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    color: rgba(0, 0, 0, 1);
    p {
    width: 100%;
    // word-wrap:break-word;
    word-break:break-all;
    // overflow: hidden;
      line-height: 50px;
      span {
        font-size: 30px;
        img {
          width: 30px;
          height: 30px;
        }
      }
    }
  }
  .item {
    display: flex;
    justify-content: space-between;
    // border-bottom: 1Px solid rgba(238, 238, 238, 1);
    font-size: 32px;
    line-height: 80px;
    span {
      width: 200px;
      text-align: left;
    }
    input {
      width: 450px;
      // height: 52px;
      text-align: right;
      font-size: 30px;
      margin-right: 0;
      color: #054a5e;
    }
    input::-webkit-input-placeholder {
      /* WebKit browsers */
      color: #999;
    }
    input:-moz-placeholder {
      /* Mozilla Firefox 4 to 18 */
      color: #999;
    }

    input::-moz-placeholder {
      /* Mozilla Firefox 19+ */
      color: #999;
    }

    input:-ms-input-placeholder {
      /* Internet Explorer 10+ */
      color: #999;
    }
  }
  .uploadimg {
    display: flex;
    justify-content: space-around;
    align-items: center;
    .upload {
      width: 240px;
      height: 240px;
      margin-top: 20px;
      border-radius: 6px;
      border: 1Px dashed #0a89ac;
      .yulan {
        width: 238px;
        height: 238px;
        display: flex;
        justify-content: center;
        align-items: center;
        img {
          width: 100%;
          height: 100%;
        }
      }
      input {
        width: 10px;
        opacity: 0;
        filter: alpha(opacity=0);
      }
      .box {
        margin: 0 auto;

        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        span {
          font-size: 24px;
          font-family: PingFangSC-Regular;
          font-weight: 400;
          color: rgba(10, 137, 172, 1);
          line-height: 80px;
        }
        .iconfont {
          font-size: 65px;
          color: #0a89ac;
        }
      }
    }
  }
  .message {
    margin: 0 auto;
    padding: 15px;
    box-sizing: border-box;
    width: 686px;
    height: 200px;
    border-radius: 4px;
    border: 1Px solid #235563;
    textarea {
      resize: none;
      width: 100%;
      height: 100%;
    }
  }
}
</style>